package com.util;

import android.content.SharedPreferences;

import com.android.ocean.security.BASE64Tool;
import com.app.DemoApplication;

public class SpLoginUtil {

	public static String LOGIN_INFO = "LOGIN_NAME";

	/**
	 * 
	 * @Description:TODO存储登录名
	 * @param loginName
	 * @return void
	 * @author zhuw
	 * @date 2013-3-14 下午5:58:08
	 */
	public static void saveLoginInfo(String loginName,String pwd) {
		try {
			SharedPreferences.Editor editor = DemoApplication.mContext
					.getSharedPreferences(LOGIN_INFO, 0).edit();
			editor.putString("login_name", BASE64Tool.encryptBASE64(loginName));
			editor.putString("dwp", BASE64Tool.encryptBASE64(pwd));
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	public static String[] getLoginInfo() {
		String []result = new String[2];
		SharedPreferences sp = DemoApplication.mContext.getSharedPreferences(
				LOGIN_INFO, 0);
		try {
			result[0] = BASE64Tool.decryptBASE64(sp.getString("login_name", ""));
			result[1] = BASE64Tool.decryptBASE64(sp.getString("dwp", ""));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;

	}
	public static void  clear() {
		try {
			SharedPreferences.Editor editor = DemoApplication.mContext
					.getSharedPreferences(LOGIN_INFO, 0).edit();
			editor.clear();
			editor.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
